package com.hkts.management.drivercomment.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import com.hkts.management.feign.FeignInterface;
import com.hkts.management.model.TO.HontUserTo;
import com.hkts.management.utils.CustomPageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.management.drivercomment.service.IDriverCommentService;
import com.hkts.management.drivercomment.entity.DriverComment;

import java.util.List;

/**
 * @author hml
 * @since 2021-05-20
 */
@RestController
@RequestMapping("/order/driverComment")
@Api(tags = "司机评论信息管理接口")
public class DriverCommentController {
    private final Logger logger = LoggerFactory.getLogger(DriverCommentController.class);

    @Autowired
    public IDriverCommentService iDriverCommentService;

    @Autowired
    private FeignInterface feignInterface;

    /**
     * 分页查询数据
     *
     * @param page          分页信息
     * @param driverComment 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getDriverCommentPageList")
    public Result<Object> getHontUserList(Page<DriverComment> page, DriverComment driverComment) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iDriverCommentService.selectPage(page, driverComment)));
    }

    /**
     * 保存和修改公用的
     *
     * @param driverComment 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/driverCommentSave")
    @ApiOperation(value = "新增司机评论")
    public Result<DriverComment> driverCommentSave(DriverComment driverComment) {

        return iDriverCommentService.saveDrverComment(driverComment);
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/driverCommentGetById")
    public Result<Object> driverCommentGetById(String id) {
        DriverComment byId = iDriverCommentService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/driverCommentDelete")
    public Result<Object> hontUserDelete(String id) {
        iDriverCommentService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/driverCommentBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iDriverCommentService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getCredit")
    public Result<Object> getCredit(String driverId){
        return iDriverCommentService.getCredit(driverId);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getCommentByOrderId")
    @ApiOperation(value = "根据订单Id获取司机评论")
    @ApiImplicitParams({@ApiImplicitParam(name = "orderId", value = "订单Id", required = true, dataType = "string")
          })
    public Result<Object> getCommentByOrderId(String orderId){
        return ResultUtil.data(iDriverCommentService.selectComment(orderId));
    }

}
